package com.company.gobang.module.room;

import com.company.gobang.module.room.domain.Room;
import xyz.noark.core.util.MapUtils;

import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * 房间管理器
 *
 * @author 小流氓[176543888@qq.com]
 */
public class RoomManager {
    private static final RoomManager instance = new RoomManager();
    private final AtomicInteger id = new AtomicInteger(1000);
    private final Map<Integer, Room> roomMap = MapUtils.newHashMap(32);

    public static RoomManager getInstance() {
        return instance;
    }

    public Room createRoom() {
        return roomMap.computeIfAbsent(id.incrementAndGet(), Room::new);
    }

    public Room getRoom(int roomId) {
        return roomMap.get(roomId);
    }
}
